#define _CRT_SECURE_NO_WARNINGS 1

#include<stdio.h>
#include<assert.h>

struct ListNode* deleteNode(struct ListNode* head, int val)
{
	assert(head);
	struct ListNode* cur = head;
	struct ListNode* prev = NULL;
	while (cur != NULL)
	{
		if (cur->val == val) {
			if (cur == head)
			{
				head = head->next;
				free(cur);
				cur = head;
			}
			else
			{
				prev->next = cur->next;
				free(cur);
				cur = prev->next;
			}
		}
		else {
			prev = cur;
			cur = cur->next;
		}
	}
	return head;
}